package com.o2o.regularservice.brand_modular_202004.utils

import org.apache.spark.sql.{DataFrame, SparkSession}

class brand_state_util {

  def brand_state(brand_stap_2:DataFrame, spark:SparkSession, platformName:String): DataFrame ={
//    新增品牌
    brand_stap_2.registerTempTable("addNewBrand")


//   品牌来源国表
    val state_1 = spark.read.option("header","true")
      .csv("s3a://o2o-dataproces-group/li_yinchao/Table/2019/brand_stateTable/brand_stateTable_end.csv")
      .dropDuplicates("brandName_cn")

//    缓存
    state_1.registerTempTable("brand_stateTables")
    val stateResult = spark.sqlContext.sql(
      """
        |select
        |a.*,
        |b.brand_state as state
        |from
        |addNewBrand a
        |left join
        |brand_stateTables b
        |on a.brandName_cn = b.brandName_cn
      """.stripMargin)
      .dropDuplicates("brandCcId")
      .drop("brand_state")
      .withColumnRenamed("state", "brand_state")

    return stateResult
  }
}
